var gulp = require('gulp')
    minifycss = require('gulp-minify-css'),  //CSS压缩
    concatFile = require('gulp-concat'),        // 文件合并
    uglify = require('gulp-uglify'),        //js压缩插件
    rename = require('gulp-rename'),        // 重命名
    notify = require('gulp-notify'),        // 重命名
    less = require('gulp-less'),        // 重命名
    plumber = require('gulp-plumber'),      // 解决报错停止
    shell = require('gulp-shell'),
    amdOptimize = require('amd-optimize');

gulp.task('watch', function() {
  gulp.watch(['./js/*.js', './js/*/*.js'], ['js-index', 'js-list', 'js-chart', 'js-chart-group']);
  gulp.watch(['./styles/*.less', './styles/*/*.less'], ['css-less']);
})

// 打包requirejs的代码
gulp.task('js-index', function () {
  return gulp.src(['./js/*.js', './js/vendor/*.js', './js/module/*.js'])
    .pipe(amdOptimize('index', {}))
    .pipe(concatFile('index.js'))
    .pipe(gulp.dest('./dist/'));
});

gulp.task('js-list', function () {
  return gulp.src(['./js/*.js', './js/vendor/*.js', './js/module/*.js'])
    .pipe(amdOptimize('list', {}))
    .pipe(concatFile('list.js'))
    .pipe(gulp.dest('./dist/'));
});

gulp.task('js-chart', function () {
  return gulp.src(['./js/*.js', './js/vendor/*.js', './js/module/*.js'])
    .pipe(amdOptimize('chart', {}))
    .pipe(concatFile('chart.js'))
    .pipe(gulp.dest('./dist/'));
});

gulp.task('js-chart-group', function () {
  return gulp.src(['./js/*.js', './js/vendor/*.js', './js/module/*.js'])
    .pipe(amdOptimize('chartGroup', {}))
    .pipe(concatFile('chartGroup.js'))
    .pipe(gulp.dest('./dist/'));
});

// 编译less
gulp.task('css-less', function() {
  return gulp.src(['./styles/*.less', './styles/*/*.less'])
      .pipe(plumber())
      .pipe(less())
      .pipe(gulp.dest('./styles/'))
      // .pipe(notify({ message: 'less2css task ok' }));
});
